<?php

namespace App\Http\Controllers;

use App\Http\Service\Douban\DoubanpostService;
use App\Http\Service\ViewcountService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;

class GuangguangController extends BaseController
{
    private $getRules=[
            'unique_id'=> 'required',
            //'city_code'=>'required',
        ];
    private  $getRulesMessage=[
            'unique_id.required'=> '唯一标识【unique_id】不能为空',
           // 'city_code.required'=> 'city_code不能为空',

        ];
    public $repository;
    public function __construct(DoubanpostService $repository,ViewcountService $historyservice)
    {
        parent::__construct();
        $this->repository = $repository;
        $this->historyservice = $historyservice;
    }
    

    /**
     *  逛逛-列表
     *  
     * @param Request $request
     * @return JsonResponse
     */
    public function getList(Request $request)
    {
        $data=[
            'title'=>$request->input("title"),
            'unit_type'=>$request->input("unit_type"),
            'is_official'=>$request->input("is_official"),
            
        ];

        $type=1;//逛逛
        $this->success($this->repository->getList($request,$data,$type));
    }

    /**
     *  逛逛-详情
     *  
     * @param Request $request
     * @return JsonResponse
     */
    public function dataDetail(Request $request)
    {
        $data=[
            'unique_id'=>$request->input("unique_id"),
            'people_id'=>$request->input("people_id"),

        ];
        $this->checkrule($data,$this->getRules,$this->getRulesMessage);
        //添加历史记录
        $hdata=$data;
        $hdata['type']='1';
        $hdata['type_son']='5';
        $first=DB::table("douban_post")->where(['unique_id'=>$data['unique_id']])->first();
        if(empty($first)){
            $this->error("帖子不存在");
        }
        //dd($first);
        $hdata['user_id']=$first->user_id;
        $hdata['title']=$first->title;
        $hdata['avatar']=$first->avatar;
        $hdata['cover']=$first->cover;
        $hdata['nickname']=$first->nickname;
        $hdata['publish_time']=$first->publish_time;
        //dd($hdata);
        //dd($hdata);
        $this->historyservice->addDate($request,$hdata);

        $this->success($this->repository->dataDetail($request,$data));
    }

    

  

}
